<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Insert title here</title>
	</head>

	<e:View id="view">
	    <script type="text/javascript">SkinUtil.getSkin();</script>
	    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
    
		<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;" >
			<e:Dataset id="Dataset_Role" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="Dataset_Role" pageSize="15" loadDataCommand="Command_Load">
				<e:Field name="roleId" dataType="string" label="角色编号" maxLength="32" required="true"/>
				<e:Field name="roleName" dataType="string" label="角色名称" maxLength="60" required="true"/>
				<e:Field name="sortNo" dataType="integer" label="排序号" maxLength="4" required="true"/>
				<e:Field name="remark" dataType="string" label="备注" maxLength="200" />
			</e:Dataset>
			
			<e:Command id="Command_Save" action="com.longtop.framework.sys.role.web.RoleListAction" method="saveRole" submitForm="true" validateRequired="true">
				<e:DatasetInfo name="DatasetInfo1" dataset="Dataset_Role" alwayRefreshClient="false" submitType="changes"></e:DatasetInfo>
			</e:Command>
			<e:Command id="Command_Search" action="com.longtop.framework.sys.role.web.RoleListAction" method="searchRole" submitForm="true" submitFormScope="all" validateRequired="true">
				<e:DatasetInfo name="DatasetInfo2" dataset="Dataset_Role" alwayRefreshClient="true" submitType="all"></e:DatasetInfo>
			</e:Command>
			<e:Command id="Command_Load" action="com.longtop.framework.sys.role.web.RoleListAction" method="loadRole" showHintInfoOnSuccess="false">
				<e:DatasetInfo name="DatasetInfo3" dataset="Dataset_Role" alwayRefreshClient="true"></e:DatasetInfo>
			</e:Command>
		</div>

		<body>
			<e:Page id="ePage" action="com.longtop.framework.sys.role.web.RoleListAction" style="min-height: 80px; width: 100%; height: 100%;" onAfterLoadPage="ePage_onAfterLoadPage()">
				<table style="width: 100%; height: 100%;" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
					<tr>
						<td align="left" valign="top">
							<e:Panel id="Panel_Search" style="width: 285px; height: 100%" caption="查询条件" captionIcon="/images/query_win.gif" captionStyle="color:#888888" allowFold="true" showArrowButton="false">
								<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" width="100%" align="center">
									<tr>
										<td width="80px" align="right">
											<e:Label id="Label_roleId" caption="角色编码"></e:Label>
										</td>
										<td>
											<e:Text id="Text_roleId" style="width:169px;"></e:Text>
										</td>
									</tr>
									<tr>
										<td align="right">
											<e:Label id="Label_roleName" caption="角色名称"></e:Label>
										</td>
										<td>
											<e:Text id="Text_roleName" style="width:169px;"></e:Text>
										</td>
									</tr>
									<tr>
										<td align="right">
											<e:Label id="Label_remark" caption="角色说明"></e:Label>
										</td>
										<td>
											<e:Text id="Text_remark" style="width:169px;"></e:Text>
										</td>
									</tr>
									<tr>
										<td></td>
										<td>
											<e:Button id="Button_Search" style='height: 22px; width: 70px' caption="查询" command="Command_Search" icon="/images/query.gif" onClick="Button_Search_onClick()"></e:Button>&nbsp;&nbsp;
											<e:Button id="Button_refush" style='height: 22px; width: 70px' caption="重置" icon="/images/refresh.gif" onClick="Button_Reset()"></e:Button>
										</td>
									</tr>
								</table>
							</e:Panel>
						</td>
						<td valign="top" width="100%">
							<e:Panel id="Panel_Result" style="width: 100%; height: 100%" captionStyle="color:#888888" caption="查询结果列表" captionIcon="/images/list_win.gif" showArrowButton="false">
								<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" >
									<tr>
										<td>
											<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
												<tr>
													<td height="27px" width="1%">
														<e:RecordNavigator id="RecordNavigator_Role" dataset="Dataset_Role" showNavigatorButton="false">
															<e:RecordButton id="RecordButton_insert" label="新增" onClick="insertRecord" icon="/images/add.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_delete" label="删除" onClick="deleteRecord" icon="/images/delete.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_save" label="保存" icon="/images/submit.gif" onClick="RecordButton_save_onClick()"></e:RecordButton>
															<e:RecordButton id="RecordButton_auth" label="分配权限" onClick="RecordButton_auth_onClick()" icon="/images/edit_win.gif"></e:RecordButton>
															<e:RecordButton id="RecordButton_user" label="分配用户" onClick="RecordButton_user_onClick()" icon="/images/edit_win.gif"></e:RecordButton>
														</e:RecordNavigator>
													</td>
													<td align="left" width="99%"><e:PageNavigator id="PageNavigator_Role" dataset="Dataset_Role" showRecordNum="true"></e:PageNavigator></td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<e:Grid id="Grid_Result" style="width: 100%; height: 458px;" showIndex="true" dataset="Dataset_Role" onClick="Grid_result_onClick()">
											</e:Grid>
										</td>
									</tr>
								</table>
							</e:Panel>
						</td>
					</tr>
			    </table>
			</e:Page>
		</body>
	</e:View>
</html>	

<script type="text/javascript">
	//init
	function ePage_onAfterLoadPage(){
		//Button_Search_onClick();
	}
	
	//查询
	function Button_Search_onClick(){
	    Command_Search.execute();
	}
	
	//重置
	function Button_Reset(){
        $J("Text_roleId").setValue("");
        $J("Text_roleName").setValue("");
		$J("Text_Remark").setValue("");
	}
	
	//保存
	function RecordButton_save_onClick(){
	    Command_Save.execute();
	}
	
	//单击记录
	function Grid_result_onClick(){
		var element = event.srcElement;
		if(element.isDataCell){
			if(element.isDataCell){
		        var currentRecord = element.record;
		        if(currentRecord.state == Constant.RECORD.STATE_NEW || currentRecord.state == Constant.RECORD.STATE_INSERT) {
	          		currentRecord.dataset.getField("roleId").setReadOnly(false);
	          	}
	          	else{
			        currentRecord.dataset.getField("roleId").setReadOnly(true);
	       		}
			}
		}
	}
	
	//分配权限
	function RecordButton_auth_onClick(){
		var dataset = $J(Dataset_Role);
	    if (!dataset) {
	        MsgBox.showInfoMsg("角色数据集不存在！");
	        return;
	    }
	    if(!dataset.getCurrentRecord()){
	    	 MsgBox.showInfoMsg("请选择要分配权限的角色！");
	   	    return;
	    }
	
	    var roleId = dataset.getCurrentRecord().getString("roleId");
	    var path ="/jsp/framework/sys/role/roleAuth.jsp?roleId="+roleId;
		openTab("roleAuth","分配权限",path);
	}	
	//分配用户
	function RecordButton_user_onClick(){
		var dataset = $J(Dataset_Role);
	    if (!dataset) {
	        MsgBox.showInfoMsg("角色数据集不存在！");
	        return;
	    }
	    var recordCurrent = dataset.getCurrentRecord();
	    if(!recordCurrent){
	    	MsgBox.showInfoMsg("请选择要分配用户的角色！");
	   	    return;
	    }
	
	    var roleId = recordCurrent.getValue("roleId");
	    var roleName;
  		if(recordCurrent.getValue("roleName")!=null&&recordCurrent.getValue("roleName")!=""){
  			roleName =Util.encode(recordCurrent.getValue("roleName"));
  		}
	    
	    var path = "/jsp/framework/sys/role/roleUser.jsp?roleId="+roleId+"&roleName="+roleName;
		openTab("roleUser","分配用户",path);
	
	}		
</script>